package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Role;
import com._51cto.healthy.service.RoleService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {
    @DubboReference
    private RoleService roleService;

    @GetMapping("/page/{pageSize}/{pageNum}")
    public R queryPageRole(@RequestParam(value = "query",required = false/*表示参数不是必填项*/) String query,
                       @PathVariable("pageNum") Integer pageNum,
                       @PathVariable("pageSize") Integer pageSize){
        P<Role> roleP = roleService.queryRoleIds(query, pageNum, pageSize);
        return R.success(roleP,"查询成功");

    }

    @PostMapping
    public R insertRole(@RequestBody Role role){
        roleService.insertRoleMenuPermission(role);
        return R.success("添加成功");
    }

    @PutMapping
    public R updateRoleMenu(@RequestBody Role role){
        roleService.updateRoleMenu(role);
        return R.success("修改成功");
    }

    @DeleteMapping("/{id}")
    public R deleteRoleMenu(@PathVariable("id") Integer id){
        roleService.deleteRoleMenu(id);
        return R.success("删除成功");
    }
}
